import java.util.*;

/**
 * Created with Gitee
 * author:ju bai
 * Date:2021/5/9
 * Time:20:58
 **/
public class Main2 {
    /**
     * 每日一题-查找两个字符串a,b中的最长公共子串
     *
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        //让str1指向较短的那个
        if (str1.length() <= str2.length()) {
            compare(str1, str2);
        } else {
            compare(str2, str1);
        }
    }

    /**
     * 查找两个字符串a,b中的最长公共子串
     * @param str1 字符串1
     * @param str2 字符串2
     */
    public static void compare(String str1, String str2) {
        String result = "";
        for (int i = 1; i < str1.length(); i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = i - 1; j < str1.length(); j++) {
                if (str2.contains(sb.append(str1.charAt(j)))) {
                    if (sb.length() > result.length()) {
                        result = sb.toString();
                    }
                }
            }
        }
        System.out.println(result);
    }
}